# coding=utf8

import os
import sys
import numpy as np


class Preliminary:

    @staticmethod
    def demo_numpy_save():
        x = np.arange(10)
        np.save('file43_save_1', x)

        with open('file43_save_2.npy', 'wb') as fobj:
            np.save(fobj, x)

    @staticmethod
    def demo_numpy_savez():
        x = np.arange(10)
        np.savez('file43_savez_1', x)

        x1 = np.arange(10)
        x2 = np.arange(10, 0, -1)
        np.savez('file43_savez_2', x1=x1, x2=x2)

    @staticmethod
    def demo_numpy_savez_compressed():
        x = np.arange(10000)
        np.savez('file43_savez_nocompressed', x=x)
        print("size of file43_savez_nocompressed:\t{}".format(os.path.getsize('file43_savez_nocompressed.npz')))
        np.savez_compressed('file43_savez_compressed', x=x)
        print("size of file43_savez_compressed:\t{}".format(os.path.getsize('file43_savez_compressed.npz')))


    @staticmethod
    def demo_numpy_load():
        x1 = np.load('file43_save_1.npy')
        print("---read from file43_savez_1.npy")
        print(x1)

        print("---read from file43_save_2.npy")
        with open('file43_save_2.npy', 'rb') as fobj:
            x3 = np.load(fobj)
            print(x3)

        x41 = np.load('file43_savez_1.npz')
        print("---read from file43_savez_1.npz")
        for x in x41.files:
            print(x)
            print(x41[x])

        x42 = np.load('file43_savez_2.npz')
        print("---read from file43_savez_2.npz")
        for x in x42.files:
            print(x)
            print(x42[x])

        x5 = np.load('file43_savez_compressed.npz')
        print("---read from file43_savez_compressed.npz")
        for x in x5.files:
            print(x)
            print(x5[x])


def task():
    pass


def expand():
    x = np.arange(100000)
    np.savez('file43_expand_savez_nocompressed', x=x)
    print("size of file43_expand_savez_nocompressed:\t{}".format(
        os.path.getsize('file43_expand_savez_nocompressed.npz')))
    np.savez_compressed('file43_expand_savez_compressed', x=x)
    print("size of file43_expand_savez_compressed: \t{}".format(
        os.path.getsize('file43_expand_savez_compressed.npz')))


if __name__ == '__main__':
    # Preliminary.demo_numpy_save()
    # Preliminary.demo_numpy_savez()
    # Preliminary.demo_numpy_savez_compressed()
    # Preliminary.demo_numpy_load()
    expand()
